package cn.doitedu.rest.api.dao;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.stereotype.Repository;

import java.io.IOException;

@Repository
public class PvEventDetailDao {
    Table table = null;
    public PvEventDetailDao() throws IOException {
        Configuration conf = HBaseConfiguration.create();
        conf.set("fs.defaultFS","hdfs://doitedu01:8020/");
        conf.set("hbase.zookeeper.quorum", "doitedu01,doitedu02,doitedu03");

        Connection conn = ConnectionFactory.createConnection(conf);
        table = conn.getTable(TableName.valueOf("pv_event_detail"));
    }


    public String getPvEventsByRowKey(String rowkey) throws IOException {
        Get get = new Get(Bytes.toBytes(rowkey));
        Result result = table.get(get);

        CellScanner cellScanner = result.cellScanner();

        String res = null;
        while(cellScanner.advance()){
            Cell cell = cellScanner.current();
            byte[] valueBytes = CellUtil.cloneValue(cell);
            res = new String(valueBytes);
        }
        return res;
    }

}
